package org.cangkuguanli.luoyuhang.controller;

import org.cangkuguanli.luoyuhang.bean.Cangku;
import org.cangkuguanli.luoyuhang.bean.Gongyingshang;
import org.cangkuguanli.luoyuhang.bean.Huowu;
import org.cangkuguanli.luoyuhang.mapper.CargoMapper;
import org.cangkuguanli.luoyuhang.mapper.GongyingshangMapper;
import org.cangkuguanli.luoyuhang.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 货物查询
 */
@RestController
@RequestMapping("/cargo")
public class CargoController {



    @Autowired
    private CargoMapper cargoMapper;


/*    // 分类展示
    @RequestMapping("/categorical")
    public JsonResult Categorical() { //参数
        //根据货物信息，分页查询  可以根据货物信息查询,名称,规格,仓库,货架,层数,状态查询
        cargoMapper.Categorical();
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }*/

    //货物查询
    @RequestMapping("/CargoInquiry")
    public JsonResult CargoInquiry(Huowu cargo) { //参数
        //根据货物信息，分页查询  可以根据货物信息查询,名称,规格,仓库,货架,层数,状态查询
        List<Huowu> huowus=  cargoMapper.CargoInquiry(cargo);
        JsonResult result = new JsonResult(true,200,huowus,"");
        return result;
    }

    //展示最新货物
    @RequestMapping("/Latest")
    public JsonResult Latest() { //参数
        //展示最新货物 qianwutiao
        List<Huowu> list = cargoMapper.Latest();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }

    //查询数量最少得货物 smallQuantities
    @GetMapping("/smallQuantities")
    public JsonResult SmallQuantities() { //参数
        //展示最新货物
        List<Huowu> list = cargoMapper.SmallQuantities();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }                                        

    //展示所有最新货物
    @GetMapping("/allLatest")
    public JsonResult allLatest() { //参数
        //展示最新货物 qianwutiao
        List<Huowu> list = cargoMapper.allLatest();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }

    //查询数量排序货物 smallQuantities
    @GetMapping("/AllSmallQuantities")
    public JsonResult AllSmallQuantities() { //参数
        //展示最新货物
        List<Huowu> list = cargoMapper.AllSmallQuantities();
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }

    //按名称进行模糊查询 smallQuantities
    @GetMapping("/name")
    public JsonResult Name(String name) { //参数
        //展示最新货物
        List<Huowu> list = cargoMapper.Name(name);
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }


    //xinzeng 新增HUowu数据 smallQuantities
    @PostMapping("/AddWarehouse")
    public JsonResult AddWarehouse(Huowu Warehouse) { //参数
        //展示最新货物
        List<Huowu> list =  cargoMapper.AddWarehouse(Warehouse);
        JsonResult result = new JsonResult(true,200,list,"");
        return result;
    }

    //货物查询上面写了

    //修改货物信息
    @PostMapping("/updWarehouse")
    public JsonResult UpdWarehouse(Cangku Warehouse) { //参数
        //展示最新货物
        cargoMapper.UpdWarehouse(Warehouse);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }


    //批量删除和单个删除
    @DeleteMapping("/delWarehouse")
    public JsonResult DelWarehouse(String ids) { //参数
        //展示最新货物
        List<String> idList = Arrays.asList(ids.split(","));
        cargoMapper.DelWarehouse(idList);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }

    // 删除仓库所有数据(不用测试)
    @DeleteMapping("/delAllWarehouse")
    public JsonResult DelAllWarehouse() { //参数
        //展示最新货物
        cargoMapper.DelAllWarehouse();
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}
